package com.qf.mvc2202.exhandler;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//@Component
public class MyExResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {

        // 打印异常信息到控制台
        System.out.println(ex);

        final ModelAndView modelAndView = new ModelAndView();

        if (ex instanceof UserException){
            // 返回用户名模块的错误提示页面
            modelAndView.setViewName("/error/usererror.jsp");
        }else {
            // 通用的报错页面
            modelAndView.setViewName("/error/error.jsp");
        }

        return modelAndView;
    }
}
